package com.qf.java2007.service.impl;

import com.qf.java2007.mapper.BookInfoMapper;
import com.qf.java2007.mapper.LendListMapper;
import com.qf.java2007.pojo.LendList;
import com.qf.java2007.service.LendListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * @Author AzureSky_X
 * @Date 2021/3/10 14:32
 * @Version 1.0
 */
@Service
@Transactional
public class LendListServiceImpl implements LendListService {
    @Autowired
    private BookInfoMapper bookInfoMapper;
    @Autowired
    private LendListMapper lendListMapper;

    @Override
    public List<LendList> findByReaderId(Long readerId) {
        List<LendList> lendLists = lendListMapper.findByReaderId(readerId);
        return lendLists;
    }

    @Override
    public List<LendList> findAllLendList() {
        List<LendList> lendLists = lendListMapper.findAllLendList();
        return lendLists;
    }

    @Override
    public void deleteLengById(Long serNum) {
        lendListMapper.deleteLengById(serNum);
    }

    @Override
    public void borrowBook(Long bookId,Long readerId,Integer number1) {
        //每次每本限借一次
        Integer number=number1-1;
        //修改图书数量
        bookInfoMapper.updateBookNum(number,bookId);
        LendList lendList=new LendList();
        lendList.setBookId(bookId);
        lendList.setLendDate(new Date());
        lendList.setReaderId(readerId);
        lendListMapper.addLend(lendList);

    }
}
